﻿using System.Collections.ObjectModel;
using System.ComponentModel;

namespace TreeView_binding {

  static class Utils {
    public static void Notify(this PropertyChangedEventHandler changed, object sender, string property) {
      if (changed != null) changed(sender, new PropertyChangedEventArgs(property));
    }
  }

  abstract public class Node : INotifyPropertyChanged {
    public Node() { Label = string.Empty; }
    public Node(string lbl) { Label = lbl; }
    public string Label { get { return label_; } set { label_ = value; PropertyChanged.Notify(this, "Label"); } }
    private string label_;

    public event PropertyChangedEventHandler PropertyChanged;
  }

  public class LeafNode : Node {
    public LeafNode(string lbl) : base(lbl) { }
  }

  public class InnerNode : Node {
    public InnerNode(string lbl) : base(lbl) { Children = new ObservableCollection<Node>(); }
    public ObservableCollection<Node> Children { get; set; }
  }

  class BindData {
    public BindData() { Tree = new ObservableCollection<Node>(); }
    public ObservableCollection<Node> Tree { get; set; }
  }

}
